package ru.st.selenium;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class AddFilm extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Test
  public void testAddFilm() throws Exception {    driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
    driver.findElement(By.name("name")).clear();
    driver.findElement(By.name("name")).sendKeys("My first film");
    driver.findElement(By.name("aka")).clear();
    driver.findElement(By.name("aka")).sendKeys("gfbcv");
    driver.findElement(By.name("year")).clear();
    driver.findElement(By.name("year")).sendKeys("2013");
    driver.findElement(By.name("duration")).clear();
    driver.findElement(By.name("duration")).sendKeys("120");
    driver.findElement(By.name("rating")).clear();
    driver.findElement(By.name("rating")).sendKeys("5");
    driver.findElement(By.id("own_no")).click();
    driver.findElement(By.id("seen_no")).click();
    driver.findElement(By.name("notes")).clear();
    driver.findElement(By.name("notes")).sendKeys("fdfdv");
    driver.findElement(By.name("taglines")).clear();
    driver.findElement(By.name("taglines")).sendKeys("gdfgsd");
    driver.findElement(By.name("plotoutline")).clear();
    driver.findElement(By.name("plotoutline")).sendKeys("fgdfg");
    driver.findElement(By.name("plots")).clear();
    driver.findElement(By.name("plots")).sendKeys("gfdfg");
    driver.findElement(By.id("text_languages_0")).clear();
    driver.findElement(By.id("text_languages_0")).sendKeys("dfgdfg");
    driver.findElement(By.name("subtitles")).clear();
    driver.findElement(By.name("subtitles")).sendKeys("dfgfg");
    driver.findElement(By.name("audio")).clear();
    driver.findElement(By.name("audio")).sendKeys("gffdgfd");
    driver.findElement(By.name("video")).clear();
    driver.findElement(By.name("video")).sendKeys("gfdgdf");
    driver.findElement(By.name("country")).clear();
    driver.findElement(By.name("country")).sendKeys("fdgfdgd");
    driver.findElement(By.name("genres")).clear();
    driver.findElement(By.name("genres")).sendKeys("dfgdgdfg");
    driver.findElement(By.name("director")).clear();
    driver.findElement(By.name("director")).sendKeys("fdgdfgdf");
    driver.findElement(By.name("writer")).clear();
    driver.findElement(By.name("writer")).sendKeys("fgdfgdd");
    driver.findElement(By.name("producer")).clear();
    driver.findElement(By.name("producer")).sendKeys("fgdfgdfgdf444");
    driver.findElement(By.name("music")).clear();
    driver.findElement(By.name("music")).sendKeys("htgbhfdtrtr55");
    driver.findElement(By.name("cast")).clear();
    driver.findElement(By.name("cast")).sendKeys("f bgty5y");
    driver.findElement(By.id("submit")).click();
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}